package com.shuhua.taskServer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shuhua.pojo.entity.TaskCollect;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

@Mapper
public interface TaskCollectMapper extends BaseMapper<TaskCollect> {
    @Select("SELECT c.*, t.*, f.username as craftsman_username, f.phone as craftsman_phone, f.real_name as craftsman_real_name, f.department as craftsman_department, f.station as craftsman_station, f.avatar as craftsman_avatar FROM task_collect c LEFT JOIN task t ON c.task_id = t.task_id LEFT JOIN craftsman f ON c.craftsman_id = f.id WHERE c.craftsman_id = #{craftsmanId}")
    List<Map<String, Object>> selectCollectWithTaskByCraftsmanId(@Param("craftsmanId") Long craftsmanId);

    @Select("SELECT c.*, t.*, f.username as craftsman_username, f.phone as craftsman_phone, f.real_name as craftsman_real_name, f.department as craftsman_department, f.station as craftsman_station, f.avatar as craftsman_avatar FROM task_collect c LEFT JOIN task t ON c.task_id = t.task_id LEFT JOIN craftsman f ON c.task_id = t.task_id AND c.craftsman_id = f.id WHERE c.task_id = #{taskId} AND c.craftsman_id = #{craftsmanId} LIMIT 1")
    Map<String, Object> selectCollectWithTaskByTaskAndCraftsman(@Param("taskId") Long taskId, @Param("craftsmanId") Long craftsmanId);

    @Select("SELECT c.*, t.*, f.username as craftsman_username, f.phone as craftsman_phone, f.real_name as craftsman_real_name, f.department as craftsman_department, f.station as craftsman_station, f.avatar as craftsman_avatar FROM task_collect c LEFT JOIN task t ON c.task_id = t.task_id LEFT JOIN craftsman f ON c.craftsman_id = f.id")
    List<Map<String, Object>> selectAllCollectWithTask();
} 